import { useToast } from 'primevue/usetoast'

/**
 * 自定义组合式API
 */
export function useCustomToast() {

  // 初始化 toast 函数
  const toast = useToast()

  /**
   * 通用显示 Toast
   * @param type 提示的类型
   * @param summary 提示的标题
   * @param detail 提示的内容
   * @param life 提示框停留的时间
   */
  function showToast(type, summary, detail, life = 5000) {
    toast.add({
      severity: type,
      summary: summary,
      detail: detail,
      group: 'headless',
      life: life
    })
  }

  return {
    // 显示成功
    showSuccess: (summary, detail, life) => showToast('success', summary, detail, life),
    // 显示失败
    showError: (summary, detail, life) => showToast('error', summary, detail, life),
    // 显示警告
    showWarn: (summary, detail, life) => showToast('warn', summary, detail, life)
  }
}